package com.example.minefieldkeepercloud.view.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ListView;
import com.example.minefieldkeepercloud.R;
import com.example.minefieldkeepercloud.adapter.YHAdapter;
import com.example.minefieldkeepercloud.bean.YHByBean;


public class BottomDialog extends Dialog {
    private Activity activity;
    private  YHByBean yhByBean;
    private YHAdapter factoryPopAdapter;
    private OnSelectListener onSelectListener;
    public BottomDialog( Activity context, YHByBean yhByBean,OnSelectListener onSelectListener) {
        super(context,R.style.DialogTheme);
        activity=context;
        this.yhByBean=yhByBean;
        this.onSelectListener=onSelectListener;
        showBottomDialog();
    }

    private void showBottomDialog(){

        //2、设置布局
        View view = View.inflate(activity,R.layout.dialog_custom_layout,null);
        setContentView(view);
        Window window = getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置弹出动画
        window.setWindowAnimations(R.style.main_menu_animStyle);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, 500);
        ListView lv_houselayout=view.findViewById(R.id.lv_houselayout);
        factoryPopAdapter = new YHAdapter(activity,yhByBean.getData());
        lv_houselayout.setAdapter(factoryPopAdapter);

        lv_houselayout.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                onSelectListener.select(yhByBean.getData().get(i).getID(),yhByBean.getData().get(i).getFullName());
                factoryPopAdapter.setSelected(i);
                dismiss();
            }
        });


    }

    public  interface OnSelectListener
    {
        public void select(int id,String name);//不限

    }
}
